fix(agents): await realtime auto tool reply in RunResult#5702
Open
longcw wants to merge 2 commits into
Open
Conversation
When `auto_tool_reply_generation=True`, the realtime model produces the tool reply via its own `generation_created` event after tools execute. The new `SpeechHandle` was created inside `_on_generation_created` and never registered with the active `RunResult`, so `await sess.run(...)` could return before the auto reply had been spoken. Install a placeholder future right before pushing tool outputs (the model can emit the new generation during/right after `update_chat_ctx`), register a watcher task with the RunResult, and resolve the placeholder in `_on_generation_created` while attaching the new handle to the run. Release the placeholder on the `update_chat_ctx` failure path so the run does not block for the timeout when no reply will arrive. A 30s timeout backstops cases where the model never generates a reply. Closes #5638
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
auto_tool_reply_generation=True, the realtime model produces the tool reply via its owngeneration_createdevent after tools execute. The newSpeechHandlewas created in_on_generation_createdbut never registered with the activeRunResult, soawait sess.run(...)could return before the auto reply had been spoken.Install a placeholder future before pushing tool outputs (the model can emit the new generation during/right after
update_chat_ctx), register a watcher task withRunResult, and resolve the placeholder in_on_generation_createdwhile attaching the new handle to the run. Release the placeholder on theupdate_chat_ctxfailure path so the run does not block for the timeout when no reply will arrive. A 5s timeout backstops cases where the model never generates a reply.Closes #5638